#include <vector>
#include <algorithm>
#include <iostream>
#include <string>

using namespace std;

//dp[i][j] j pair in i
int main()
{
    int n, k;
    while (cin >> n >> k)
    {
        vector<int> ws(n + 1);
        for (int i = 1; i <= n; i++)
            cin >> ws[i];
        sort(ws.begin() + 1, ws.end());

        vector<vector<int>> dp(n + 1, vector<int>(k + 1, INT_MAX / 2));
        for (int i = 0; i <= n; i++)
            dp[i][0] = 0;

        for (int i = 2; i <= n; i++)
            for (int j = 1; j <= k; j++)
                dp[i][j] = min(dp[i - 1][j],
                               dp[i - 2][j - 1] + (ws[i] - ws[i - 1]) * (ws[i] - ws[i - 1]));

        cout << dp[n][k] << endl;
    }

    return 0;
}
/*  
i-2,j-1
        i-1,j
        i,j

6 3
1 1 2 2 2 2
*/